<template>
  <div class="contaienr">
    
  </div>
</template>

<script>
import { getAppid } from '@/api'
export default {
  name: 'HelloWorld',
  data () {
    return {
      authUrl:process.env.ENV,//
      appId:"",
    }
  },
  created(){
    document.title = "授权中"
  },
  methods:{
    getAppid(){
      localStorage.removeItem("access-token");
    	let data = {
    		officialName:localStorage.officialName
    	}
    	getAppid(data).then(res=>{
        if(res.success){
          this.appId = res.data;
          this.getUserCode();
        }
    	})
    },
    // 向微信发送code请求
    getUserCode() {
      //  let toUrl =window.location.href;
      //   //原始地址
      //   let originUrl = toUrl.split("reference");
      //   let res = originUrl[1].replace('=','');
      //   let clearCode = res.split("&code");
      //   let returnUrl = clearCode[0];
      //   window.localStorage.setItem('returnUrl',returnUrl);
				//向微信发起获取code的请求 成功会重定向到我们的redirectUrl
        // const url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+ this.appId +'&redirect_uri='+this.authUrl+ '/redirect'+ returnUrl + '&response_type=code&scope=snsapi_userinfo&state=reference#wechat_redirect'
          let url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+ this.appId +'&redirect_uri='+this.authUrl+ encodeURIComponent('/loading') + '&response_type=code&scope=snsapi_userinfo&state=reference#wechat_redirect'
          window.location.href=url;	
			}
  },
  mounted(){
    this.getAppid();
  }
}
</script>
<style scoped>

</style>